package gk.example.adapter;

import gk.example.App;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.gkdate.R;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 
 * Description:主页面菜单适配器
 * 
 * @author Wenk.Chan（最新修改者）
 * @version 1.0（最新版本号）
 */
public class MainMenuAdapter extends BaseAdapter {
	public static final int ITEMS = 6;
	private Context mContext;

	public MainMenuAdapter(Context context) {
		mContext = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return ITEMS;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		MainMenuViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new MainMenuViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_drop_down_menu_main, parent, false);

			viewHolder.TvTitle = (TextView) convertView
					.findViewById(R.id.tv_main_menu_item_title);
			viewHolder.ImagePicture = (CircleImageView) convertView
					.findViewById(R.id.iv_main_menu_item_picture);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (MainMenuViewHolder) convertView.getTag();
		}
		switch (position) {
		case 0:
			LayoutParams params = viewHolder.ImagePicture.getLayoutParams();
			params.height = 96;
			params.width = 96;
			viewHolder.ImagePicture.setLayoutParams(params);
			viewHolder.TvTitle.setText(App.BmobUser.getNickName());
			if (App.BmobUser.getUserHead() != null) {
				App.BmobUser.getUserHead().loadImageThumbnail(mContext,
						viewHolder.ImagePicture, 70, 70, 70);
			} else {
				viewHolder.ImagePicture
						.setImageResource(R.drawable.default_round_head);
			}

			break;
		case 1:
			viewHolder.ImagePicture
					.setImageResource(R.drawable.ic_main_menu_setting);
			viewHolder.TvTitle.setText(R.string.setting);
			break;
		case 2:
			viewHolder.ImagePicture
					.setImageResource(R.drawable.ic_main_menu_feedback);
			viewHolder.TvTitle.setText(R.string.feedback);
			break;
		case 3:
			viewHolder.ImagePicture
					.setImageResource(R.drawable.ic_main_menu_exit);
			viewHolder.TvTitle.setText(R.string.share);
			break;
		case 4:
			viewHolder.ImagePicture
					.setImageResource(R.drawable.ic_main_menu_exit);
			viewHolder.TvTitle.setText(R.string.about);
			break;
		case 5:
			viewHolder.ImagePicture
					.setImageResource(R.drawable.ic_main_menu_exit);
			viewHolder.TvTitle.setText(R.string.exit);
			break;
		default:
			break;
		}
		return convertView;
	}
}

class MainMenuViewHolder {
	CircleImageView ImagePicture;
	TextView TvTitle;
}
